using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Administration_Toolkit_v2
{
    public partial class ResxFileHistory : Form
    {
        public ResxFileHistory()
        {
            InitializeComponent();
        }

        private void ResxFileHistory_Load(object sender, EventArgs e)
        {
            dgResxFileHistory.AutoGenerateColumns = false; 
            dgResxFileHistory.DataSource = Utilities.GetResxFileHistoryList();
        
        }

     
        private void dgResxFileHistory_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                string ApplicationName;
                string CultureName;
                string DataSourceName;
                int Build;
                string FileName;
                string DirectoryName;
                if (e.ColumnIndex == 5)
                {
                    if (txtDirectory.Text == null || txtDirectory.Text == String.Empty)
                    {
                        txtStatus.Text = "Please enter a directory name to export to.";
                    }
                    else if (txtFileName.Text.Trim() == null || txtFileName.Text.Trim() == String.Empty)
                    {
                        txtStatus.Text = "Please enter a file name to export to.";
                    }
                    else
                    {
                        ApplicationName = ((DataGridView)(sender))["ApplicationName", e.RowIndex].Value.ToString();
                        CultureName = ((DataGridView)(sender))["CultureName", e.RowIndex].Value.ToString();
                        DataSourceName = ((DataGridView)(sender))["DataSourceName", e.RowIndex].Value.ToString();
                        Build = System.Convert.ToInt32(((DataGridView)(sender))["Build", e.RowIndex].Value);
                        FileName = txtFileName.Text.Trim();
                        DirectoryName = txtDirectory.Text.Trim();
                        if (!(DirectoryName[DirectoryName.Length - 1].Equals(@"\")))
                        {
                            DirectoryName += @"\"; 
                        }
                        Utilities.ExportVersionedResxFile(ApplicationName, CultureName, DataSourceName, Build, DirectoryName+FileName);
                        txtStatus.Text = "File Exported";
                    }
                }
            }
            catch (Exception ex)
            {
                txtStatus.Text  = ex.Message;  
            }
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnSelectDirectory_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.ShowDialog();
            txtDirectory.Text = folderBrowserDialog1.SelectedPath;
        }

        

      
    }
}